<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system 
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : order_process_fixprice.class.php   FILE_PATH : E:\www\\trunk\classes\application\order_process_fixprice.class.php
 * ....交易流程操作类	交易类型:拍卖
 * 
 * array(
 * 	'retrun_type'=>'url',	返回类型  url 或者 showpage
 * 	'retrun_info'=>,	返回内容 url 或者页面名称
 * 	'url_type'=>'location',	url返回类型  location 直接跳转，redirect 经过跳转页面
 *  'url_message'=>'' 跳转页面显示信息
 * );
 * 
 * array(
 * 	'error'=>'1',//有错误
 * 	'error_msg'=>'',//错误提示
 * );
 * 
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Thu Feb 26 09:16:26 CST 2009
 */

defined('Base_Use_Sign') or die("this is invalid system!please contact <a href='http://www.shopnc.net'>www.shopnc.net</>.");

require_once('order.class.php');

class OrderProcessAuction extends ProductOrderClass {
	/**
	 * 订单内容
	 *
	 * @var obj
	 */
	var $order_info;
	/**
	 * 支付方式交易流水号
	 *
	 * @var obj
	 */
	var $alipay_id;
	/**
	 * 语言包内容
	 *
	 * @var obj
	 */
	var $lang;
	
	/**
	 * 构造函数
	 * 
	 * @author workflow Develop Team     
	 * @param  $sp_code 订单编号
	 * @return array
	 */
	function OrderProcessFixprice($sp_code=''){
		$this->__construct($sp_code);
	}
	function __construct($sp_code=''){
		//取订单信息
		if ($sp_code != ''){
			$this->order_info = $this->getOneOrderBySpcode($sp_code);			
		}
		//初始化变量
		$this->_getConfiginfo();
	}
	
	/**
	 * 商品详情页面点击购买操作，信息输出到购买页面
	 * @author workflow Develop Team     
	 * @param  $param	传递参数
	 * @return array	输出到页面的信息
	 */
	function buy($param){
		require_once("bid.class.php");
		$obj_product_bid = new BidClass();
		//拍卖的情况，获取下次竞拍出价价格
		//判断该用户的竞拍状态是否是领先，如果是领先的则不能出价
		$condition_bid['bid_member_id'] = $_SESSION['s_login']['id'];
		$condition_bid['p_code'] = $param['item_id'];
		$condition_bid['bid_state'] = array('1','2');
		$bid_array = $obj_product_bid->getProductBidList($condition_bid,$page);
		if (!empty($bid_array)){
			return array(
				'error'=>'1',//有错误
				'error_msg'=>$this->_lang['errNotCompetition'],//错误提示
			);
		}

		if("" != $param['buy_now']){
			//判断是否使用系统自定义加价幅度，1为使用
			if($param['p_system_step'] == "1"){
				require_once("up_price.class.php");
				$obj_up_price = new UpPriceClass();
				//取商品加价幅度
				$increment = $obj_up_price->getIncrementUpprice($param['buy_now']);
				$increment_row['increment'] = $increment?$increment:1;
			}else{
				$increment_row['increment'] = $param['p_price_step'];
			}
			$param['increment'] = $increment_row['increment'];
			$param['min_price'] = $param['buy_now'] + $increment_row['increment'];
		}else{
			$param['buy_now'] = $param['old_price'];
		}
		//最小出价
		if($param['min_price'] == ''){
			$param['min_price'] = $param['buy_now'];
		}
		unset($obj_product_bid,$obj_up_price);
		return $param;
	}
	
	/**
	 * 获取订单状态 
	 * 
	 * 说明：
	 * 取得订单状态，根据状态获取下一步操作的url(next_url)，文字等内容
	 * 返回信息 用来输出页面
	 * 用于列表等展示
	 * 
	 * array(
	 * 	'state_title'=>'',//状态名称
	 * 	'state_url'=>'',//下一步的url
	 * 	'state_type'=>'',//类别，卖家还是买家使用该URL	seller,buyer,all
	 * );
	 * 
	 * @author workflow Develop Team     
	 * @param  $sp_code 订单编号
	 * @return array
	 */
	function order($param){
		/**
		 * 判断是否使用代理出价
		 */
		$buy_price = $param["min_price"];//最低出价
		$pay_price = $param["txtPayPrice"];//当前出价
		if($buy_price < $pay_price){
			$param["max_price"] = $pay_price;
		}
		//出价记录对象
		require_once("bid.class.php");
		$obj_product_bid = new BidClass();
		//商品对象
		require_once('product.class.php');
		$obj_product = new ProductClass();
		//会员对象
		require_once('member.class.php');
		$obj_member = new MemberClass();
		//提醒对象
		require_once('remind.class.php');
		$obj_remind = new RemindClass();
		
		
		/**
		 * 单件拍卖
		 */
		if($param["p_storage"] == '1'){
			/**
			 * 更新出局出价记录状态
			 */
			$bid_product["p_code"] = $param["txtPcode"];
			$agent_bid = $obj_product_bid->agentBid($bid_product);//取领先的信息，领先状态，有心理价位（出价在竞拍价格之上），单件领先的信息只有一个
			if(count($agent_bid) > 0){//如果有 领先竞拍记录数量
				//存在代理出价
				$agent_input["txtBuyerId"] = $agent_bid[0]["bid_member_id"];
				$agent_input["txtPcode"] = $agent_bid[0]["bid_p_code"];
				$agent_input["max_price"] = $agent_bid[0]["bid_max_price"];
				$agent_input["min_price"] = $agent_bid[0]["bid_price"];
				$agent_input["txtBuyNum"] = $agent_bid[0]["bid_count"];
				$agent_input["txtReceiveId"] = $agent_bid[0]["bid_receive_code"];
				$agent_input["bid_state"] = $agent_bid[0]["bid_state"];
				$agent_input["anonymous"] = $agent_bid[0]["bid_anonymous"];//为了和购买页面的表单名称相同
				
				//更新出局出价记录状态
				$bid_out = $obj_product_bid->updateProductBidStateInCondition($bid_product);

				//代理出价者出价信息
				$agent_last_bid = $agent_input;//代理出价，也就是目前最高的出价者信息
				$user_last_bid = $param;//当前买家出价的信息
				
				if("" != $param["max_price"]){//买家出价大于最低出价

					if($agent_input["max_price"] < $param["max_price"]){//当前出价大于领先出价

						for($i=0; (($buy_price+$i*$param["step_price"]) <= $agent_input["max_price"]) || ((($buy_price+$i*$param["step_price"]) > $agent_input["max_price"]) && ($agent_input["max_price"] + $param["step_price"] > ($buy_price+$i*$param["step_price"]))); $i++){
							$user_temp_bid = $user_last_bid;
							$this_min_price = $buy_price+($i)*$param["step_price"];
							//保存当前出价用户代理出价记录
							$user_temp_bid["max_price"] = "";
							if($user_last_bid["max_price"] <= $this_min_price){
								$user_temp_bid["bid_state"] = "1";
								$user_temp_bid["min_price"] = $user_last_bid["max_price"];
							}else{
								$user_temp_bid["bid_state"] = "0";
								$user_temp_bid["min_price"] = $this_min_price;
							}
							$user_temp_bid["bid_time"] = time() + $i;
							$user_bid_result = $obj_product_bid->saveProductBid($user_temp_bid);

							//保存代理出价用户代理出价记录
							$agent_last_bid["max_price"] = "";
							if($agent_input["max_price"] <= $this_min_price){
								$agent_last_bid["bid_state"] = "0";
								$agent_last_bid["min_price"] = $agent_input["max_price"];
							}else{
								$agent_last_bid["bid_state"] = "0";
								$agent_last_bid["min_price"] = $this_min_price;
							}
							$agent_last_bid["bid_time"] = time() + $i + 1;
							$agent_bid_result = $obj_product_bid->saveProductBid($agent_last_bid);
						}

						if($user_temp_bid["bid_state"] == "0"){
							//保存用户最高出价记录
							$user_this_bid = $param;
							$user_this_bid["bid_state"] = "1";
							if($param["max_price"] >= ($this_min_price + $param["step_price"])){
								$user_this_bid["max_price"] = $param["max_price"];
								$user_this_bid["min_price"] = $this_min_price + $param["step_price"];
							}else{
								$user_this_bid["max_price"] = "";
								$user_this_bid["min_price"] = $param["max_price"];
							}
							$user_this_bid["bid_time"] = time() + $i + 2;
							$user_bid_result = $obj_product_bid->saveProductBid($user_this_bid);
						}
						//当前价格
						$cur_price = $user_this_bid["min_price"];
					}elseif($agent_input["max_price"] == $param["max_price"]){
						for($i=0; (($buy_price+$i*$param["step_price"]) <= $agent_input["max_price"]) || ((($buy_price+$i*$param["step_price"]) > $agent_input["max_price"]) && ($agent_input["max_price"] + $param["step_price"] > ($buy_price+$i*$param["step_price"]))); $i++){
							$user_temp_bid = $user_last_bid;
							$this_min_price = $buy_price+($i)*$param["step_price"];
							//保存当前出价用户代理出价记录
							$user_temp_bid["max_price"] = "";
							if($user_last_bid["max_price"] <= $this_min_price){
								$user_temp_bid["bid_state"] = "0";
								$user_temp_bid["min_price"] = $user_last_bid["max_price"];
							}else{
								$user_temp_bid["bid_state"] = "0";
								$user_temp_bid["min_price"] = $this_min_price;
							}
							$user_temp_bid["bid_time"] = time() + $i;
							$user_bid_result = $obj_product_bid->saveProductBid($user_temp_bid);

							//保存代理出价用户代理出价记录
							$agent_last_bid["max_price"] = "";
							if($agent_input["max_price"] <= $this_min_price){
								$agent_last_bid["bid_state"] = "1";
								$agent_last_bid["min_price"] = $agent_input["max_price"];
							}else{
								$agent_last_bid["bid_state"] = "0";
								$agent_last_bid["min_price"] = $this_min_price;
							}
							$agent_last_bid["bid_time"] = time() + $i + 1;
							$agent_bid_result = $obj_product_bid->saveProductBid($agent_last_bid);
						}
						//当前价格
						$cur_price = $agent_last_bid["min_price"];
					}else{
						for($i=0; (($buy_price+$i*$param["step_price"]) <= $param["max_price"]) || ((($buy_price+$i*$param["step_price"]) > $param["max_price"]) && ($param["max_price"] + $param["step_price"] > ($buy_price+$i*$param["step_price"]))); $i++){
							$user_temp_bid = $user_last_bid;
							$agent_temp_bid = $agent_last_bid;
							$this_min_price = $buy_price+($i)*$param["step_price"];
							//保存当前出价用户代理出价记录
							$user_temp_bid["max_price"] = "";
							if($user_last_bid["max_price"] <= $this_min_price){
								$user_temp_bid["bid_state"] = "0";
								$user_temp_bid["min_price"] = $user_last_bid["max_price"];
							}else{
								$user_temp_bid["bid_state"] = "0";
								$user_temp_bid["min_price"] = $this_min_price;
							}
							$user_temp_bid["bid_time"] = time() + $i;
							$user_bid_result = $obj_product_bid->saveProductBid($user_temp_bid);
							/*保存代理出价用户代理出价记录*/
							$agent_temp_bid["max_price"] = "";
							if($agent_input["max_price"] <= $this_min_price){
								$agent_temp_bid["bid_state"] = "1";
								$agent_temp_bid["min_price"] = $agent_input["max_price"];
								$agent_this_bid["min_price"] = $agent_temp_bid["min_price"];
							}elseif($user_last_bid["max_price"] <= $this_min_price){
								$agent_temp_bid["bid_state"] = "1";
								$agent_temp_bid["max_price"] = $agent_input["max_price"];
								$agent_temp_bid["min_price"] = $this_min_price;
								$agent_this_bid["min_price"] = $agent_temp_bid["min_price"];
							}else{
								$agent_temp_bid["bid_state"] = "0";
								$agent_temp_bid["min_price"] = $this_min_price;
							}
							$agent_temp_bid["bid_time"] = time() + $i + 1;
							$agent_bid_result = $obj_product_bid->saveProductBid($agent_temp_bid);
						}

						if($agent_temp_bid["bid_state"] == "0"){
							/*保存用户最高出价记录*/
							$agent_this_bid = $agent_last_bid;
							$agent_this_bid["bid_state"] = "1";
							if($agent_last_bid["max_price"] >= ($this_min_price + $param["step_price"])){
								$agent_this_bid["max_price"] = $param["max_price"];
								$agent_this_bid["min_price"] = $this_min_price + $param["step_price"];
							}else{
								$agent_this_bid["max_price"] = "";
								$agent_this_bid["min_price"] = $param["max_price"];
							}
							$agent_this_bid["bid_time"] = time() + $i + 2;
							$agent_bid_result = $obj_product_bid->saveProductBid($agent_this_bid);
						}
						//当前价格
						$cur_price = $agent_this_bid["min_price"];
					}
				}else{
					if($agent_input["max_price"] < $buy_price){
						$agent_last_bid["bid_state"] = "0";
						$param["bid_state"] = "1";
						//保存代理出价用户代理出价记录
						$agent_last_bid["max_price"] = "";
						$agent_last_bid["min_price"] = $agent_input["max_price"];
						$bid_result = $obj_product_bid->saveProductBid($agent_last_bid);
						//保存用户此次出价记录
						$bid_result = $obj_product_bid->saveProductBid($param);
						//当前价格
						$cur_price = $buy_price;
					}elseif($agent_input["max_price"] == $buy_price){
						$agent_last_bid["bid_state"] = "1";
						$param["bid_state"] = "0";
						//保存用户此次出价记录
						$bid_result = $obj_product_bid->saveProductBid($param);
						//保存代理出价用户代理出价记录
						$agent_last_bid["max_price"] = "";
						$agent_last_bid["min_price"] = $buy_price;
						$bid_result = $obj_product_bid->saveProductBid($agent_last_bid);
						//当前价格
						$cur_price = $buy_price;
					}else{
						$agent_last_bid["bid_state"] = "0";
						$param["bid_state"] = "0";
						//保存用户此次出价记录
						$bid_result = $obj_product_bid->saveProductBid($param);
						//保存代理出价用户代理出价记录
						$agent_last_bid["max_price"] = "";
						$agent_last_bid["min_price"] = $buy_price;
						$bid_result = $obj_product_bid->saveProductBid($agent_last_bid);
						//保存代理出价用户领先出价记录
						$agent_this_bid = $agent_input;
						$agent_this_bid["bid_state"] = "1";
						if($agent_input["max_price"] > ($buy_price + $param["step_price"])){
							$agent_this_bid["max_price"] = $agent_input["max_price"];
							$agent_this_bid["min_price"] = $buy_price + $param["step_price"];
						}else{
							$agent_this_bid["max_price"] = "";
							$agent_this_bid["min_price"] = $agent_input["max_price"];
						}
						$bid_result = $obj_product_bid->saveProductBid($agent_this_bid);
						//当前价格
						$cur_price = $agent_this_bid["min_price"];
					}
				}
				//更新拍卖商品当前价格
				$product_cur["p_code"] = $param["txtPcode"];
				$product_cur["cur_price"] = $cur_price;
				$product_cur["ifupdatebidnum"] = 1;
				$update_product_cur_price = $obj_product->updateProductCurPrice($product_cur);
			}else{
				$bid_out = $obj_product_bid->updateProductBidStateInCondition($bid_product);
				$param["bid_state"] = 1;
				$bid_result = $obj_product_bid->saveProductBid($param);
				//更新拍卖商品当前价格
				$product_cur["p_code"] = $param["txtPcode"];
				$product_cur["cur_price"] = $param["min_price"];
				$product_cur["ifupdatebidnum"] = 1;
				$update_product_cur_price = $obj_product->updateProductCurPrice($product_cur);
			}
		}else{
			/**
			 * 多件拍卖
			 */
			$count = $param["txtBuyNum"];
			$p_storage = $param["p_storage"];//库存
			$bid_product["p_code"] = $param["txtPcode"];
			//记录竞拍信息
			$bid_array = array();
			$bid_array['txtBuyerId'] = $_SESSION['s_login']['id'];//竞拍会员
			$bid_array['txtPcode'] = $param["txtPcode"];//竞拍商品
			$bid_array['max_price'] = $param["max_price"];//心理价位
			$bid_array['min_price'] = $param["txtPayPrice"];//竞拍单价
			$bid_array['txtBuyNum'] = $count;//购买数量
			$bid_array['txtReceiveId'] = $param["txtReceiveId"];//收费地址编号
			$bid_array['bid_state'] = 1;
			$bid_array['anonymous'] = $param["anonymous"];//是否匿名
			$obj_product_bid->saveProductBid($bid_array);
			unset($bid_array);
			//取出所有竞拍该商品处于领先状态的竞拍信息
			$condition_bid['p_code'] = $param["txtPcode"];
			$condition_bid['bid_state'] = 1;
			$condition_bid['order'] = 2;
			$bid_array = $obj_product_bid->getProductBidList($condition_bid,$page);
			//更新竞拍次数
			$product_bid_count["p_code"] = $param["txtPcode"];
			$product_bid_count["bid_num"] = count($bid_array);
			$update_product_bid_count = $obj_product->updateProductBidCount($product_bid_count);
			
			//整理竞拍信息 商品总数为$p_storage
			if (is_array($bid_array)){
				$line = 0;//领先的竞拍信息的商品数量
				$array = array();
				foreach ($bid_array as $k => $v){
					$line+=$v['bid_count'];
					if ($line<=$p_storage){//处于商品数量范围以内的，如果超出，则算最后一位拍卖商品数量不足,再后面的都不计算在内
						$array[] = $v;
					}else {
						break;
					}
				}
			}
			//判断最后一位是否是竞拍商品数量不足，如果是则发站内信
			if (($line-$p_storage)<$bid_array[count($array)]['bid_count']){//则说明最后一位是购买数量不足,并且该竞拍信息的状态不变化
				//网站提醒
//				$this->_remind($this->order_info['p_code'],'above_notice');
				
				$condition = '';
				$condition['p_code'] = $param['txtPcode'];
				$condition['state'] = "none";
				$product_array = $obj_product->getProductList($condition, $obj_page);//取商品信息
				$condition['id'] = $bid_array[count($array)]['bid_member_id'];
				$member_array = $obj_member->getMemberInfo($condition);//取会员信息
				$value_array = array();
				$value_array['username'] = $member_array['login_name'];
				$value_array['product_name'] = $product_array[0]['p_name'];
				$obj_remind->setMessageOrMail('buyer_bid_above_notice','bid_above_notice',$value_array,$member_array['login_name'],$this->_configinfo);//当我的出价被超过时，请通知我
				
				//拍卖商品数量不足的竞拍信息
				$array[count($array)] = $bid_array[count($array)];
			}
			//取需要把状态变为出局的竞拍信息
			//$array = @array_diff_key($bid_array,$array);
			if (!function_exists('array_diff_key')){
					$result = $bid_array;
			        foreach ($bid_array as $v1) {
			            foreach ($array as $key => $v) {
			                if (array_key_exists($key, $v1)) {
			                    unset($result[$key]);
			                }
			            }
			        }
			        $array = $result;
			}else{
				$array = @array_diff_key($bid_array,$array);
			}

			if (is_array($array)){
				foreach ($array as $k => $v){
					$input_param = array();
					$input_param['bid_state'] = 0;
					$input_param['bid_id'] = $v['bid_id'];
					$obj_product_bid->updateProductBidState($input_param);
				}
			}
		}
		return array(
			'retrun_type'=>'url',
			'retrun_info'=>'member/own_product_list.php?action=auction',
			'url_type'=>'redirect',
			'url_message'=>$this->_lang['alertProductBuySuccess'],
		);
	}
	
	/**
	 * 获取订单状态 
	 * 
	 * 说明：
	 * 取得订单状态，根据状态获取下一步操作的url(next_url)，文字等内容
	 * 返回信息 用来输出页面
	 * 用于列表等展示
	 * 
	 * @author workflow Develop Team     
	 * @param  $sp_code 订单编号
	 * @return array
	 */
	function getOrderStateInfo($sp_code){
		if ($this->order_info != ''){
			$this->__construct($sp_code);
		}
		require_once("payment.class.php");
		$obj_payment = new PaymentClass();
		//根据状态
		switch ($this->order_info['sp_state']){
			case '0'://等待买家付款
				//判断支付方式跳转链接
				return array(
					'state_title'=>$this->_lang['langOrderWaitBuyPayment'],
					'state_url'=>$this->_configinfo['websit']['site_url'].'/member/own_order.php?action=bid_sel_payment&sp_code='.$this->order_info['sp_code'],
					'state_type'=>'buyer',
				);
				break;
			case '1'://买家已支付
				//判断支付方式跳转链接
				$payment_array = $obj_payment->returnPaymentPath($this->order_info['sp_pay_mechod'],$sp_code,1,$this->order_info['receive_code'],$this->order_info['sp_state']);
				break;
			case '2'://卖家已发货
				//判断支付方式跳转链接
				$payment_array = $obj_payment->returnPaymentPath($this->order_info['sp_pay_mechod'],$sp_code,2,$this->order_info['receive_code'],$this->order_info['sp_state']);
				break;
			case '3'://买家已收货
				$payment_array = $obj_payment->returnPaymentPath($this->order_info['sp_pay_mechod'],$sp_code,2,$this->order_info['receive_code'],$this->order_info['sp_state']);
				break;
			case '6'://交易失败
				$payment_array = $obj_payment->returnPaymentPath($this->order_info['sp_pay_mechod'],$sp_code,2,$this->order_info['receive_code'],$this->order_info['sp_state']);
			case '7'://交易关闭
				$payment_array = array(
					'state_title'=>$this->_lang['langOrderStateClose'],
					'state_url'=>'',
					'state_type'=>'all',
				);
				break;
		}
		unset($obj_payment);
		return $payment_array;
	}
	
	/**
	 * 改变订单状态
	 * 
	 * 说明:
	 * 竞拍的状态分为 已购买，已支付，已发货，已收货，交易失败
	 * 已购买状态 是生成订单的基本状态，不用改变，从已支付状态开始改变，已收货状态为最后的完成交易状态
	 * 
	 * @author workflow Develop Team     
	 * @param  $sp_code 订单编号	$to_state	改变到的状态
	 * @return bool
	 */
	function changeOrderState($sp_code,$to_state){
		switch ($to_state){
			case '0'://买家已购买
				//订单改变为该状态的时候需要调用的具体方法，返回需要使用的信息，比如链接，输出等信息
				
				break;
			case '1'://买家已支付
				$result = $this->_changeOrderStatePayed($sp_code);
				break;
			case '2'://卖家已发货
				$result = $this->_changeOrderStateSetInvoice($sp_code);
				break;
			case '3'://买家确认收货
				//成功完成购买操作
				CreditsClass::saveCreditsLog('succ_buy',$this->order_info['buyer_id']);
				$result = $this->_changeOrderStateReceived($sp_code);
				break;
		}
		return $result;
	}
	
	/**
	 * 私有方法 更新商品信息
	 * @author workflow Develop Team     
	 * @param  $param 商品编号等信息
	 * @return bool
	 */
	function _updateProduct($param){
		//更新商品售出数量,如达到商品发布数量商品下架
		if($param["allow_quantity"] == $param["txtBuyNum"]){
			$param["have_sold_all"] = 1;
		}else{
			$param["have_sold_all"] = 0;
		}
		$param["p_code"] = $param["txtPcode"];
		$param["decrease_num"] = $param["txtBuyNum"];//减少的数量
		//更新商品当期售出数量和累计售出数量
		require_once('product.class.php');
		$obj_product = new ProductClass();
		$result = $obj_product->updateProductSoldCount($param);
		unset($obj_product);
		return $result;
	}
	
	/**
	 * 私有方法 提醒操作
	 * 
	 * 说明：提醒种类	add_order	生成订单
	 * 
	 * @author workflow Develop Team     
	 * @param  $p_code 商品编号 $remind_type 提醒种类
	 * @return int/bool/object/array
	 */
	function _remind($p_code,$remind_type){
		/**
		 * 网站提醒操作
		 */
		require_once('remind.class.php');
		$obj_remind = new RemindClass();
		//取商品信息
		require_once('product.class.php');
		$obj_product = new ProductClass();
		$condition['p_code'] = $p_code;
		$array = $obj_product->getProductList($condition,$page,'member');
		$product_array = $array[0];
		//提醒类别
		switch ($remind_type){
			case 'above_notice':
				$condition = '';
				$condition['p_code'] = $param['txtPcode'];
				$condition['state'] = "none";
				$product_array = $obj_product->getProductList($condition, $obj_page);//取商品信息
				$condition['id'] = $bid_array[count($array)]['bid_member_id'];
				$member_array = $obj_member->getMemberInfo($condition);//取会员信息
				$value_array = array();
				$value_array['username'] = $member_array['login_name'];
				$value_array['product_name'] = $product_array[0]['p_name'];
				$obj_remind->setMessageOrMail('buyer_bid_above_notice','bid_above_notice',$value_array,$member_array['login_name'],$this->_configinfo);//当我的出价被超过时，请通知我
				break;
			case 'add_order'://生成订单
				
				break;
			case 'set_invoice'://卖家发货，提醒买家
				require_once('member.class.php');
				$obj_member = new MemberClass();
				$condition['id'] = $this->order_info['buyer_id'];//买家ID
				$buyer_array = $obj_member->getMemberInfo($condition);
				$value_array = array ();
				$value_array ['username'] = $product_array['shopmaster'];
				$value_array ['product_name'] = $product_array['p_name'];
				$obj_remind->setMessageOrMail ( 'buyer_sale_to_succ', 'sale_to_succ', $value_array, $buyer_array ['login_name'], $this->_configinfo );
				unset($obj_member);
				break;
		}
		unset($obj_remind,$obj_product);
		return true;
	}
	
	
	/**
	 * 私有方法 修改订单状态 已支付
	 * @author workflow Develop Team     
	 * @param  $sp_code 订单编号 alipay_id交易流水号
	 * @return bool
	 */
	function _changeOrderStatePayed($sp_code){
		//更改订单状态,变成已发货
		$array = array();
		$array['spcode'] = $sp_code;
		$array['txtSPstate'] = 1;
		$array['pay_time'] = time ();
		$array['alipay_id'] = $this->alipay_id;
		$result = $this->updateProductOrderState($array);
		return $result;
	}
	
	/**
	 * 私有方法 修改订单状态 已发货
	 * @author workflow Develop Team     
	 * @param  $sp_code 订单编号
	 * @return bool
	 */
	function _changeOrderStateSetInvoice($sp_code){
		//卖家发货，提醒买家
		$this->_remind($this->order_info['p_code'],'set_invoice');
		//更改订单状态,变成已发货
		$array = array();
		$array['spcode'] = $sp_code;
		$array['txtSPstate'] = 2;
		$array['deliver_time'] = time ();
		$result = $this->updateProductOrderState($array);
		return $result;
	}
	
	/**
	 * 私有方法 修改订单状态 确认收货
	 * @author workflow Develop Team     
	 * @param  
	 * @return int/bool/object/array
	 */
	function _changeOrderStateReceived($sp_code){
		
		//预存款开启，并且支付方式为预存款
		if ($this->order_info['sp_pay_mechod'] == 'predeposit'){
			//确认收货，生成预付款明细，卖家为增加可用资金，买家为减少冻结资金
			require_once ("predeposit.class.php");
			$obj_predeposit = new PredepositClass ( );
			require_once("member.class.php");
			$obj_member = new MemberClass();
			//卖家
			$value_array = array ();
			$value_array ['predeposit_type'] = '3'; //卖出入账
			$value_array ['predeposit_state'] = '1';
			$value_array ['member_id'] = $this->order_info ['seller_id'];
			$value_array ['available_amount'] = $this->order_info ['total_price'];
			$value_array ['to_member_id'] = $this->order_info ['buyer_id'];
			$value_array ['sp_code'] = $this->order_info ["sp_code"];
			$value_array ['system_remark'] = $this->_lang['langOProductSold'];
			$value_array ['create_time'] = time ();
			$value_array ['update_time'] = time ();
			$value_array ['payment'] = 'predeposit';
			$obj_predeposit->addPredepositDetail ( $value_array );
			unset ( $value_array);
			//对卖家帐号进行操作
			$value_array = array ();
			$value_array ['available_predeposit'] = '+' . $this->order_info ['total_price'];
			$obj_member->modifyMember ( $value_array, $this->order_info ['seller_id'], 'predeposit' );
			unset ( $value_array );
			//买家
			$value_array = array ();
			$value_array ['predeposit_type'] = '2'; //购买商品
			$value_array ['predeposit_state'] = '1';
			$value_array ['member_id'] = $this->order_info ['buyer_id'];
			$value_array ['to_member_id'] = $this->order_info ['seller_id'];
			$value_array ['sp_code'] = $this->order_info ["sp_code"];
			$value_array ['freeze_amount'] = '-' . $this->order_info ['total_price'];
			$value_array ['system_remark'] = $this->_lang['langOProductBuy'];
			$value_array ['create_time'] = time ();
			$value_array ['update_time'] = time ();
			$value_array ['payment'] = 'predeposit';
			$obj_predeposit->addPredepositDetail ( $value_array );
			unset ( $value_array );
			//对买家帐号进行操作
			$value_array = array ();
			$value_array ['freeze_predeposit'] = '-' . $this->order_info ['total_price'];
			$obj_member->modifyMember ( $value_array, $this->order_info ['buyer_id'], 'predeposit' );
			unset ( $value_array );
			unset($obj_predeposit,$obj_member);
		}
		//更改订单状态,变成已发货
		$array = array();
		$array['spcode'] = $sp_code;
		$array['txtSPstate'] = 3;
		$array['deliver_time'] = time ();
		$array['receive_time'] = time ();
		if ($this->order_info['sp_pay_mechod'] == 'offline') {
			$array['pay_time'] = time ();
		}
		$result = $this->updateProductOrderState($array);
		return $result;
	}
}
?>